﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Buscar Paciente
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">
        $('document').ready(function () {
            $('.footer').hide();
            $('.footer').fadeIn('5000');
            $('#searchTextbox').corner('30px');
            $('#searchTextbox').mask("999-9999999-9");

            $('#searchTextbox').keydown(function (event) {
                if (event.keyCode == 13) {
                    jsonSearch();
                    ClearOldSearchResult();
                }
            });

            $('#searchButton').click(function () {
                jsonSearch();
                ClearOldSearchResult();

            });

            function jsonSearch() {
                var id = $('#searchTextbox').val();
                $.getJSON("Patient/GetPatient/?id=" + id + "", function (patient) {
                    if (patient.Name != null) {
                        $('#searchPatient').hide();
                        var content = '';
                        content += '<p class="patient">'
                        content += 'Nombre:' + ' ' + patient.Name + '<br />';
                        content += 'Apellido:' + ' ' + patient.LastName + '<br /><br />';
                        content += "<a href=Patient/DetailPatient/?id=" + patient.Id + ">" + "Consultar Paciente </a> | ";
                        content += "<a href=EmergencyForm/AddEmergencyForm/?pPatientId=" + patient.Id + ">" + "Ver formulario de Consulta </a>";
                        content += "| <a href=Patient/DeletePatient/?id=" + patient.Id + ">" + "Borrar Paciente </a>";
                        content += '</p>'
                        $('.searchHead').append(content);
                    } else {
                        var contentError = '';
                        contentError += '<p>' + patient + '</p>';
                        $('.searchHead').append(contentError);
                    }
                    $('#searchPatient').corner();
                    $('#searchPatient').addClass('searchPatientStyle');
                    $('#searchPatient').fadeIn('slow');

                });

            }

            function ClearOldSearchResult() {
                if ($('#searchPatient').is(':visible')) {
                    $('p').remove();
                    $('#searchPatient').hide();
                }
            }

            /* Implementacion de validacion en construccion
            function validateSearchTextBox() {
            if ($('#searchTextbox').val() == null) {
            $('#searchTextbox').tooltip();
            return true;
            } else {
            return false;
            }
            }
            */
        });
    </script>
    <div class="header">
        <h4>
            Buscar Paciente</h4>
    </div>
    <div id="login" class="login-ui">
        <a href="#">Login</a></div>
    <div class="main">
        <fieldset class="main-style">
            <label class="label-search">
                Buscar:</label><br />
            <input type="text" id="searchTextbox" size="50" class="search ui-corner-tl" />
            <input type="button" id="searchButton" value="Buscar" />
        </fieldset>
    </div>
    <div id="searchPatient" class="main-style">
        <div class="searchHead" id="searchHead">
        </div>
    </div>
    <div class="footer">
        <h4>
            Acciones</h4>
        <fieldset class="main-style2">
            <%: Html.ActionLink("Agregar un paciente","AddPatient")%>
            |
            <%: Html.ActionLink("Agregar un Doctor","AddDoctor","Doctor") %>
            |
            <%: Html.ActionLink("Agregar un seguro","AddInsurance","Insurance") %>
            |
            <%: Html.ActionLink("Tracking de pacientes","TrackPatient","Patient") %>
        </fieldset>
    </div>
</asp:Content>
